package com.changyuyang.intorceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.servlet.HandlerInterceptor;

import com.cyyang.shop.bean.Admin;

public class LoignIntercepter implements HandlerInterceptor{

	@Autowired
	RedisTemplate<String, Admin> redisTemplate;
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		Admin admin = redisTemplate.opsForValue().get("user");
		if (admin!=null) {
			return true;
		}
		request.getRequestDispatcher("/toLogin").forward(request, response);
		return false;
	}
}
